from flask import Blueprint,request,jsonify
from RealProject.db_init import db,Model,session
from app.user.models import User
#url会自动加上url_prefix的值
bp = Blueprint('user',__name__,url_prefix='/user')


@bp.route('/add', methods=['POST'])
def add():
    name = request.json.get('name')
    user = User(name=name)
    session.add(user)
    session.commit()
    return jsonify({'msg': '添加成功',"code":200})

@bp.route('/list', methods=['GET'])
def list():
    users = User.query.all()
    return jsonify({'users': [u.name for u in users]})